//
//  SWUpDownButton.swift
//  SinaWeibo
//
//  Created by wszyxc on 16/7/21.
//  Copyright © 2016年 wszyxc. All rights reserved.
//
 /// 创建文字和图片上下排布的button

import UIKit

class SWUpDownButton: UIButton {
    

      
    
        //重载初始化方法;
    init(imageName:String,selectImageName:String,title:String,frame:CGRect,isSelected:Bool,target:AnyObject?,action:Selector) {
        
        super.init(frame: frame)
        
        self.setImage(UIImage(named: imageName)?.imageWithRenderingMode(.AlwaysOriginal), forState: .Normal)
        
        self.setImage(UIImage(named: selectImageName), forState: .Selected)
        
        self.setTitle(title, forState: .Normal)
        
        titleLabel?.textAlignment = NSTextAlignment.Center
        
        titleLabel?.font = UIFont.systemFontOfSize(10)
        
        titleLabel?.textColor = THEMECOLOR
        
        self.contentEdgeInsets = UIEdgeInsetsMake(-5, 0, 5, 0)
        
        self.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        self.selected = isSelected
        
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        //重新布局子控件
        let btnW = frame.size.width
        
//        let btnH = frame.size.height

        imageView?.frame.size.width = 40
        imageView?.frame.size.height = 40
        
        imageView?.center.x = btnW/2
        
        titleLabel?.frame = CGRectMake(0, 38, btnW, 9)
   
    }
    

    
    

}
